package com.example.manpower.Mapper;

import com.example.manpower.Dto.DepartmentEmployeeCount;
import com.example.manpower.Entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
* @author asus
* @description 针对表【user】的数据库操作Mapper
* @createDate 2024-10-11 09:56:26
* @Entity com.example.manpower.Entity.User
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
    // 查询部门总数
    @Select("SELECT COUNT(DISTINCT department_id) FROM department")
    Long selectDistinctDepartmentCount();

    // 自定义查询，假设你有一个 Department 实体与 User 实体
    @Select("SELECT new com.example.dto.DepartmentEmployeeCount(d.name, COUNT(u)) " +
            "FROM Department d LEFT JOIN d.employees u GROUP BY d.id")
    List<DepartmentEmployeeCount> countEmployeesByDepartment();
}




